Skip to content

Comments

Improve logs when recovering from an interrupted installation#4725

Draft
FranciscoTGouveia wants to merge 1 commit intorust-lang:mainfrom
FranciscoTGouveia:logs-interruped-install
Draft

Improve logs when recovering from an interrupted installation#4725
FranciscoTGouveia wants to merge 1 commit intorust-lang:mainfrom
FranciscoTGouveia:logs-interruped-install

Conversation

@FranciscoTGouveia
Copy link
Contributor

@FranciscoTGouveia FranciscoTGouveia commented Feb 20, 2026

Related to #4724.

Currently, when a toolchain installation is retried after being interrupted, an excessive number of warnings are emitted.

This patch detects that situation, skips the redundant warnings, and prints a single, more informative message instead.

I would appreciate any feedback on the wording of the new message.


For reference, I leave below the before and after:

Before:

$ rustup toolchain install 1.90 --no-self-update
info: syncing channel updates for 1.90-x86_64-unknown-linux-gnu
info: latest update on 2025-09-18 for version 1.90.0 (1159e78c4 2025-09-14)
info: removing previous version of component rustc
warn: component rustc not found during uninstall
info: removing previous version of component cargo
warn: component cargo not found during uninstall
info: removing previous version of component rust-std
warn: component rust-std not found during uninstall
info: removing previous version of component rust-docs
warn: component rust-docs not found during uninstall
info: removing previous version of component rustfmt
warn: component rustfmt not found during uninstall
info: removing previous version of component clippy
warn: component clippy not found during uninstall
info: downloading 6 components
        rustc installed                       78.70 MiB
        cargo installed                       10.18 MiB
     rust-std installed                       27.77 MiB
    rust-docs installed                       20.49 MiB
      rustfmt installed                        2.15 MiB
       clippy installed                        4.33 MiB
  1.90-x86_64-unknown-linux-gnu installed - rustc 1.90.0 (1159e78c4 2025-09-14)

After:

$ rustup toolchain install 1.90 --no-self-update
info: syncing channel updates for 1.90-x86_64-unknown-linux-gnu
info: latest update on 2025-09-18 for version 1.90.0 (1159e78c4 2025-09-14)
info: recovering from a partially installed toolchain
info: downloading 6 components
        rustc installed                       78.70 MiB
        cargo installed                       10.18 MiB
     rust-std installed                       27.77 MiB
    rust-docs installed                       20.49 MiB
      rustfmt installed                        2.15 MiB
       clippy installed                        4.33 MiB
  1.90-x86_64-unknown-linux-gnu installed - rustc 1.90.0 (1159e78c4 2025-09-14)

@FranciscoTGouveia FranciscoTGouveia changed the title fix(toolchain): improve logs when recovering from an interrupted inst… Improve logs when recovering from an interrupted installation Feb 20, 2026
for component in update.components_to_uninstall {
// If there are no components installed, we don't need to keep
// checking, we can simply exit the loop earlier.
if self.installation.list()?.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in principle this fix is correct, thanks!

However, isn't .list() doing a FS read every time in this loop? I'd imagine the result of .installation.list() to be perfectly predictable (don't care about ToC/ToU for now), so may I ask what do we have in .components_to_uninstall and .installation.list() here?

In other words, could these be two sets of elements of the same format, so that we can make a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, .list() implies a FS read, so a reasonable solution may be to enter the loop only if .list() is not empty (i.e., by adding a conditional check before the loop).

so may I ask what do we have in .components_to_uninstall and .installation.list() here?

In this case, as the toolchain was not installed, .components_to_uninstall was set to all the 6 components (see here), and .installation.list() was empty.

That said, I think a better approach would be to restrict the components_to_uninstall vector to only include components that actually exist; this comment may be misleading in that regard.
This would eliminate the need for the additional check and further simplify the uninstall_component function.

What do you think about this approach?

Copy link
Member

@rami3l rami3l Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rethinking about it I found out that I might need to be more careful about the aforementioned approach. Could this loop be written this way to defend against the interrupted in-flight state where the component is partially in-place but not appended to the final list yet?

If that is the case, maybe those checks are not to be skipped since otherwise the installation later on will fail (due to the previous version not being uninstalled)... and we should simply downgrade those warning messages to a lower logging level (say debug) and concatenating the info messages? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants